#[macro_use]
extern crate rocket;

mod action;
mod data;
mod fairing;
mod guard;
mod ipc;
mod model;
mod route;
mod token;

use crate::{
    fairing::{
        cors::Cors,
        device::{DeviceDb, DeviceDbInitializer},
        geoip::GeoIP,
        record::{RecordDb, RecordDbInitializer},
        user::{UserDb, UserDbInitializer},
    },
    route::{device, login, record, user},
    token::load_key,
};
use fairing::ipc::Ipc;
use rocket_db_pools::Database;

#[launch]
async fn rocket() -> _ {
    load_key().await.unwrap();

    rocket::build()
        .attach(UserDb::init())
        .attach(UserDbInitializer)
        .attach(RecordDb::init())
        .attach(RecordDbInitializer)
        .attach(DeviceDb::init())
        .attach(DeviceDbInitializer)
        .attach(Ipc::new())
        .attach(GeoIP)
        .attach(Cors)
        .mount("/", login::route())
        .mount("/user", user::route())
        .mount("/record", record::route())
        .mount("/device", device::route())
}
